package com.lhy.ltss.config;

import com.alibaba.fastjson.JSONObject;
import com.lhy.ltss.exception.BookSearchException;
import com.lhy.ltss.exception.LoginException;
import com.lhy.ltss.util.ResultJson;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @description:
 * @author: 李汇远
 */
@RestControllerAdvice
public class SelfExceptionAdvice  {
    // 处理空指针
    @ExceptionHandler(NullPointerException.class)
    public JSONObject nullPoint(NullPointerException e){
        e.printStackTrace();
        return ResultJson.fail("参数出现异常空值！");
    }
    // 处理登录异常
    @ExceptionHandler(LoginException.class)
    public JSONObject loginHandler(LoginException e){
        e.printStackTrace();
        return ResultJson.fail(e.getMessage());
    }
    // 访问解析图书馆页面时可能有异常
    @ExceptionHandler(BookSearchException.class)
    public JSONObject bookSearchHandler(BookSearchException e){
        e.printStackTrace();
        return ResultJson.fail(e.getMessage());
    }
}
